#include "smTexture1D.h"
#include "smError.h" 

namespace ShaderManager
{

smTexture1D::smTexture1D(GLuint texture_unit)
: smTexture(texture_unit)
{

}

void smTexture1D::bind()
{
	glBindTexture(GL_TEXTURE_1D,id);
}

void smTexture1D::unbind()
{
	glBindTexture(GL_TEXTURE_1D,0);
}

void smTexture1D::load(int size, void *data, GLuint internal_format, GLuint format, GLuint type, bool linear, bool clamp)
{
	active();
	bind();

	glTexImage1D(
			GL_TEXTURE_1D,
			0, //Mipmap : aucun
			internal_format, //GL_RGB16
			size,
			0, //Largeur du bord : 0
			format, //GL_RGB,
			type,
			data);


	if(clamp)
	{
		glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE  );
	}
	else
	{
		glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	}

	if(linear)
	{
		glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	}
	else
	{
		glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	}

	CheckGLError("Texture1D::load");
}

}